package com.hfh;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author hfh
 * @Date 2022 09 14 10 15
 **/
public class Demo1 {
    public static void main(String[] args) throws Exception {
        Class<Student> clazz = Student.class;
        Constructor<Student> constructor = clazz.getDeclaredConstructor(String.class);
        constructor.setAccessible(true);//修改访问权限
        Student student = constructor.newInstance("private有参构造");
        student.test();

        /*Class<Student> clazz = Student.class;
        Student student = clazz.getConstructor(String.class).newInstance("这是什么");
        student.test();*/

        /*Class<?> clazz = Student.class;
        Student student = (Student) clazz.newInstance();
        student.test();*/
    }
    static class Student{
        private Student(String str){

        }
        public void test(){
            System.out.println("test");
        }
    }
}
